package com.example.blogdemo

import android.content.Intent
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.example.blogdemo.databinding.ActivityMainBinding

abstract class BaseListActivity : AppCompatActivity() {
    val arrays = mutableListOf<ClickItem>()
    lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initArray(arrays)
        binding.listMan.setOnItemClickListener { adapterView, view, i, l ->
            arrays[i].click()
        }
        binding.listMan.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrays)
    }

    abstract fun initArray(arrays: MutableList<ClickItem>)
    fun openActivity(java: Class<*>, bundle: Bundle = bundleOf()) {
        val intent = Intent(this, java)
        intent.putExtras(bundle)
        startActivity(intent)
    }

    override fun onDestroy() {
        super.onDestroy()
        arrays.clear()

    }

}